package cn.itsource.ymcc.producer;

import cn.itsource.ymcc.constant.CourseConstants;
import cn.itsource.ymcc.constant.MediaConstants;
import cn.itsource.ymcc.domain.CourseDoc;
import cn.itsource.ymcc.result.JsonResult;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CourseMessageProducer implements ICourseMessageProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Override
    public void sendMessage(CourseDoc courseDoc) {
        String info1 = " 邮箱 您关注的"+courseDoc.getName()+"课程已经上线了，请到XX网址查看详细";
        String info2 = " 手机 您关注的"+courseDoc.getName()+"课程已经上线了，请到XX网址查看详细";
        String info3 = " 站内信 您关注的"+courseDoc.getName()+"课程已经上线了，请到XX网址查看详细";

        rocketMQTemplate.syncSend(CourseConstants.TOPIC_COURSE_MESSAGE_EMAIL+":"+CourseConstants.TAGS_COURSE_MESSAGE_EMAIL,
                MessageBuilder.withPayload(info1).build());
        rocketMQTemplate.syncSend(CourseConstants.TOPIC_COURSE_MESSAGE_SMS+":"+CourseConstants.TAGS_COURSE_MESSAGE_SMS,
                MessageBuilder.withPayload(info2).build());
        rocketMQTemplate.syncSend(CourseConstants.TOPIC_COURSE_MESSAGE_SYSTEM+":"+CourseConstants.TAGS_COURSE_MESSAGE_SYSTEM,
                MessageBuilder.withPayload(info3).build());
        log.info("记录你想记录的东西");
    }
}
